package com.ly.gof.create.singleton;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuyang
 * @des 有限多例模式
 * @Version 1.0
 * @Date: 20/07/2021 15:40
 */
public class Multiton {
    private static List<Multiton> multitonList = new ArrayList<>();
    private static int INSTANCE_MAX = 10;

    static {
        for (int i = 0; i < INSTANCE_MAX; i++) {
            multitonList.add(new Multiton());
        }
    }

    private Multiton() {
    }

    public static Multiton getInstance() {
        int random = (int)(Math.random() * INSTANCE_MAX);
        return multitonList.get(random);
    }
}
